#ifndef __CUDA_HOOK_TRACE_PERF_H__
#define __CUDA_HOOK_TRACE_PERF_H__

#include <chrono>
#include <string>

#include "macro.h"

class TracePerf {
public:
    TracePerf(const std::string& name) : _name(name), _start(std::chrono::steady_clock::now()) {
        HLOG("%s enter", _name.c_str());
    }

    ~TracePerf() {
        auto _end      = std::chrono::steady_clock::now();
        auto _duration = std::chrono::duration_cast<std::chrono::microseconds>(_end - _start);
        auto _micros   = static_cast<double>(_duration.count()) * std::chrono::microseconds::period::num 
                            / static_cast<double>(std::chrono::microseconds::period::den);
        HLOG("%s exit, cost %.3lf ms.", _name.c_str(), _micros);
    }
private:
    const std::string _name;
    std::chrono::steady_clock::time_point _start;
    HOOK_DISABLE_COPY_AND_ASSIGN(TracePerf) 
}; 


#ifdef  HOOK_BUILD_DEBUG
#define HOOK_TRACE_PERF(name) TracePerf _tp_##name_(name)
#else
#define HOOK_TRACE_PERF(name)
#endif

#endif // __CUDA_HOOK_TRACE_PERF_H__